/* --- ESC control ---*/
// arming of ESC 电调的保险
// 一开始给电调供电时, 信号值必须大于等于1ms 对应的电机会发出蜂鸣声 properly armed
// 如果刚开始信号值大于1ms, 之后信号要先低于1ms, 之后电机才会工作
#include <Servo.h>
// using <Servo.h>, we can easily produce 50Hz PWM signal
Servo ESC;  // create servo object to produce PWM signal to control the ESC

int potValue;  // value from the analog pin

void setup() {
  // attach(pin, min pulse width, max pulse width)
  ESC.attach(9, 1000, 2000);
  // 在这里定义好脉冲宽度的范围 1000-2000us(micoseconds)
  // potentiometer connected to pin 9
}

void loop() {
  potValue = analogRead(A0);
  potValue = map(potValue, 0, 1023, 0, 180);
  // send signal to ESC
  // 0-180 refer to 1000-2000 defined before
  ESC.write(potValue);
}